home *** CD-ROM | disk | FTP | other *** search
- @2YET ANOTHER PROBLEM FROM MR GIBSON!
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- @3
- FROM: Dave Kirk (Apex Systems)
- @4
-
- Andy is now coding a search option for Disk Mag Creator. His
- problem is how to do a case insensitive search through a text file.
-
- There's two possibilities here.
- @3
-
- Solution Number 1 - use of Arrays.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~@5
-
- When writing Disk System, each line of a text file was stored in a
- large array (something like LINE$(2000) I seem to remember). Each
- one of these held a single line of text, so searching was easy.
-
- @1
- All I did was something like this (I haven't got the source in
- front of me, this is from memory!) :-
-
-
- @1 Input "Enter string to search for:";USER$
- LINES=2000
- FOUND=0
- TEMPA$=Upper$(USER$)
- For C=1 to LINES
- TEMPB$=Upper$(LINE$(C))
- I=Instr(TEMPB$,TEMPA$)
- If I<>0
- Print "Pattern found at line";C
- Add FOUND,1
- End If
- Next C
- If FOUND=0
- Print "Search pattern not found!"
- Endif
- @4
-
- That's the basic principle of using arrays to search. Don't type
- this example into the editor though, because it won't do anything
- as it is. You would first need to set up an array containing your
- text document, LINE$(2000) for example. You may need to set a
- larger variable buffer (Set Buffer xx) to do this.
-
-
- @3 Solution Number 2 - Converting the entire document to upper case.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- @4This solution is only a theory, as I haven't had time to test or
- write a routine to do it yet. Basically, you will need two memory
- banks. The first one holds your document in it's original form,
- and the second one is a kind of temporary buffer which holds the
- entire document but in UPPER CASE.
- @1
- Here's the theory:-
- @5
- 1. Load your text file into, say, bank 10, using the Bload command.
- 2. Create a temporary bank like this:-
-
- Reserve as data 11,Length(10)
-
- 3. Now we need to convert it to upper case. This program should
- do the job just fine, although I haven't actually tried it:-
- @1
- For C=0 to Length(10)
- T=Peek(Start(10)+C)
- If T>96 And T<123 ;Lower case characters use 97-122
- Poke Start(11)+C,T-32 ;Change to UPPER CASE equivalent
- End If
- Next
-
- @4
- If my theory is correct, you should now have an exact copy of your
- document, but completely in UPPER CASE. You will then be able to
- convert your search string to UPPER CASE, and simply do a memory
- search (using "Hunt") that way.
- @3
- This method has no real disadvatages, but two points to note are:-
- @5
- 1. You will need enough space to store your text file twice over -
- once for bank 10 (the original doc), and again for bank 11
- (the document converted to UPPER CASE).
- 2. The longer your text file is, the longer it takes to convert to
- UPPER CASE, although PEEKing and POKEing is very quick, so this
- shouldn't cause too many problems.
-
- @1
- SUMMARY
- ~~~~~~~@4
- The basic idea behind doing a case insensitive search is that you
- have to do a comparison between the search string and the document.
- Before this, you need to convert both the search string and the
- document to UPPER case.
-
- @4This applies to whichever of the two methods shown above you choose
- to adapt, whether checking just one line of text at a time using
- the "Instr" command, as in example 1, or using the "Hunt" command
- to look through an entire document as in example 2.
- @5
- Thanx for the tips Dave. I too came up with the same idea as in
- Example 2 above and it works fine. However, your code to convert
- text to UPPERCASE isn't perfect!
-
- It's far easier to use LDos command @3(Lstr) @5like so:@1
-
- Reserve As Work 11,Length(10)
- ALL$=Upper$(Lstr(Start(10),Length(10))) : Rem ** LDOS Required!
- Poke$ Start(11),ALL$+Chr$(10) : Rem ** Amos Pro Required!
- Bank Swap 10,11
- @5
- Please also note that the @3Poke$ @5command is Amos Pro only and one
- which I have used from day one of programming in Amos. (In fact, I
- needed this command, so upgraded to Amos Pro to use it!)
-
- I think CRAFT has a POKE$ command (or similar) so you could
- probably use that, all you Classic Amos Users.
-
- Andy Gibson. @1End.